home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / MSG Demo 1.2 Source / MSG Demo ƒ / MSG Shell ƒ / msg dialogs.c < prev    next >
Text File  |  1993-11-10  |  3KB  |  85 lines

  1. /**********************************************************************\
  2.  
  3. File:        msg dialogs.c
  4.  
  5. Purpose:    This module handles positioning a dialog on the screen as
  6.             per Human Interface Guidelines.  Also, a quick-and-dirty
  7.             default button outline.
  8.  
  9.  
  10. MSG Demo -- graphic effects demonstration program
  11. Copyright (C) 1992-3 Mark Pilgrim & Dave Blumenthal
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program in a file named "GNU General Public License".
  25. If not, write to the Free Software Foundation, 675 Mass Ave,
  26. Cambridge, MA 02139, USA.
  27.  
  28. \**********************************************************************/
  29.  
  30. #include "msg dialogs.h"
  31.  
  32. /******************************************************************************
  33.  PositionDialog
  34.  
  35.         Center the bounding box of a dialog or alert in the upper third
  36.         of the screen.  This is the preferred location according to the
  37.         Human Interface Guidelines.
  38.  ******************************************************************************/
  39.  
  40. void    PositionDialog(ResType theType, short theID)
  41. {
  42.     Handle                theTemplate;    /* Handle to resource template        */
  43.     register Rect        *theRect;        /* Bounding box of dialog            */
  44.     register short        left;            /* Left side of centered rect        */
  45.     register short        top;            /* Top side of centered rect        */
  46.     
  47.         /* The first field of the resource template for DLOG's and ALRT's */
  48.         /* is its bounding box.  Get a pointer to this rectangle.  This   */
  49.         /* handle dereferencing is safe since the remaining statements in */
  50.         /* this function do not move memory (assignment and simple math). */
  51.  
  52.     theTemplate = GetResource(theType, theID);
  53.     if(theTemplate == 0)
  54.         return;
  55.     theRect = (Rect*) *theTemplate;
  56.     
  57.                                         /* Center horizontally on screen    */
  58.     left = (screenBits.bounds.right - (theRect->right - theRect->left)) / 2;
  59.  
  60.                                         /* Leave twice as much space below    */
  61.                                         /*   as above the rectangle            */    
  62.     top = (screenBits.bounds.bottom - (theRect->bottom - theRect->top)) / 3;
  63.                                         /* Don't put rect under menu bar    */
  64.     if(top < (GetMBarHeight() + 1))
  65.         top = GetMBarHeight() + 1;
  66.  
  67.     theRect->right += left - theRect->left;
  68.     theRect->left = left;
  69.     theRect->bottom += top - theRect->top;
  70.     theRect->top = top;
  71. }
  72.  
  73. pascal void OutlineDefaultButton(DialogPtr myDlog, short itemNum)
  74. {
  75.     short    itemType;
  76.     Handle    itemH;
  77.     Rect    box;
  78.     
  79.     GetDItem(myDlog, 1, &itemType, &itemH, &box);
  80.     PenSize(3, 3);
  81.     InsetRect(&box, -4, -4);
  82.     FrameRoundRect(&box, 16, 16);
  83.     PenNormal();
  84. }
  85.